package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.R;
import com.itheima.domain.Setmeal;
import com.itheima.dto.SetmealDto;
import com.itheima.service.SetmealDishService;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @Autowired
    private SetmealDishService setmealDishService;

    //套餐新增功能
    @PostMapping
    public R addSetmeal(@RequestBody SetmealDto setmealDto){
        setmealService.addSetmeal(setmealDto);
        return R.success("添加成功");
    }

    //套餐条件分页查询
    @GetMapping("/page")
    public R findByPage(Integer page,Integer pageSize,String name){
        Page<SetmealDto> lists = setmealService.findByPage(page,pageSize,name);
        return R.success(lists);
    }

    //套餐批量逻辑删除
    @DeleteMapping
    public R delectIds(Long[] ids){
        setmealService.delectIds(ids);
        return R.success("删除成功");
    }

    //根据分类ID查询套餐
    @GetMapping("/list")
    public R findList(Setmeal setmeal){
        List<Setmeal> setmeals = setmealService.findList(setmeal);
        return R.success(setmeals);
    }

    //套餐批量停售
    @PostMapping("/status/0")
    public R update(Long[] ids){
        R r = setmealService.modify(ids);
        return r;
    }

    //套餐批量起售
    @PostMapping("/status/1")
    public R update1(Long[] ids){
        R r = setmealService.modify1(ids);
        return r;
    }

    //套餐修改  回显
    @GetMapping("/{id}")
    public R findAll(@PathVariable Long id){
        SetmealDto setmealDto = setmealService.setmealDtoById(id);
        return R.success(setmealDto);
    }

    //套餐修改
    @PutMapping
    public R updateAll(@RequestBody SetmealDto setmealDto){
        setmealService.updateSetmealDto(setmealDto);
        return R.success("修改成功");
    }
}
